package ru.braim.weather_app.models;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import ru.braim.weather_app.models.enums.WeatherCondition;
import ru.braim.weather_app.utils.validators.DateTimeValidator;

import java.time.LocalDateTime;
import java.util.List;

@Entity
@Getter
public class WeatherForecast {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    private LocalDateTime dateTime;

    @Setter
    private Float temperature;

    @Setter

    @Enumerated(EnumType.STRING)
    private WeatherCondition weatherCondition;

    @ManyToOne
    @JoinColumn(name = "region_id", nullable = false)
    @Setter
    private Region region;

    @ManyToMany(mappedBy = "weatherForecast")
    private List<Weather> weather;


    public boolean setLocalDateTime(LocalDateTime localDateTime) {

        if (localDateTime == null) {
            return false;
        }

        if (DateTimeValidator.getValidDateTime(localDateTime.toString()) == null) {
            return false;
        }

        this.dateTime = localDateTime;
        return true;
    }


}
